import DAL from './dal.js'
import utilTools from './util.js'
import CryptoFile from "./CryptoFile.js";

// /**
//  * 查询A01表，跟人员信息相关的方法
//  */
class A01DAL {

    constructor() {
        this.init();
    };

    sayHello() {
        console.log('hello')
    }

    init() {
        this.dal = new DAL();
        this.util = new utilTools();
        this.aCryptoFile = new CryptoFile();

    };

    //在js中 数组和json应该是一样的，数组可以当作key是0 1 2 的json
    toCanRead(originalJsonInfoArray) {
        //console.log(originalJsonInfoArray)
        let canReadArray = new Array();
        for (let key in originalJsonInfoArray) {

            let originalJson = originalJsonInfoArray[key];//这个才是真正的json

            let temp = {};
            for (let item in originalJson) {
                if(originalJson[item]==null||originalJson[item]=='null'){
                    originalJson[item]='';
                }

                if (this.util.A01Dictionary[item]) {
                    if (originalJson[item]) {
                        if (this.shouldDecryptField[this.util.A01Dictionary[item]]) {
                            //解密
                            //let ecryptString = originalJson[item];
                            let ecryptItems = originalJson[item].split('@1@2');
                            //console.log(ecryptItems)
                            let decryptString = '';
                            for (let i = 0; i < ecryptItems.length - 1; i++) {
                                decryptString += this.aCryptoFile.decrypt(ecryptItems[i]);
                            }
                            //console.log(decryptString)
                            temp[this.util.A01Dictionary[item]] = decryptString;//aCryptoFile.decrypt(originalJson[item])
                        } else {
                            temp[this.util.A01Dictionary[item]] = originalJson[item].toString().trim();
                        }
                    } else {
                        temp[this.util.A01Dictionary[item]] = '';
                    }

                }

            }
            //处理一下学历信息

            temp['HighestFulltimeAcademicQualification'] = temp['QRZXL']
            temp['HighestFulltimeDegreeLevel'] = temp['QRZXW']
            let QRZXLXX = temp['QRZXLXX'];//院校系专业（最高在职学历
            let QRZXWXX = temp['QRZXWXX'];//院校系专业（最高在职学位）
            if (QRZXLXX == QRZXWXX) {
                temp['FulltimeSchoolAndMajor'] = QRZXLXX;
            } else {
                if(QRZXLXX==''){
                    temp['FulltimeSchoolAndMajor'] = QRZXWXX;
                }else if(QRZXWXX==''){
                    temp['FulltimeSchoolAndMajor'] = QRZXLXX;
                }else{
                    let tempschool = QRZXLXX + '\r\n' + QRZXWXX;
                    temp['FulltimeSchoolAndMajor'] = tempschool;
                }

            }


            temp['HighestInServiceAcademicQualification'] = temp['ZZXL']
            temp['HighestInServiceDegreeLevel'] = temp['ZZXW']

            let ZZXLXX = temp['ZZXLXX'];//院校系专业（最高在职学历
            let ZZXWXX = temp['ZZXWXX'];//院校系专业（最高在职学位）
            if (ZZXLXX == ZZXWXX) {
                temp['InServiceSchoolAndMajor'] = ZZXLXX;
            } else {
                if(ZZXLXX==''){
                    temp['InServiceSchoolAndMajor'] = ZZXWXX;
                }else if(ZZXWXX==''){
                    temp['InServiceSchoolAndMajor'] = ZZXLXX;
                }else{
                    let tempschool = ZZXLXX + '\r\n' + ZZXWXX;
                    temp['InServiceSchoolAndMajor'] = tempschool;
                }


            }


            canReadArray.push(temp)
        }
        return canReadArray;
    }

    shouldDecryptField = {'PersionName': 1};

    //#region 查询个数
    /**
     * 返回指定性别的人数
     * @param {Object} sex 性别 男 女
     */
    async SelectCountBySex(sex) {
        let conditionString = `WHERE A0163 = \'现职人员\' and A0104 = \'${sex}\'  `;

        return await this.dal.androidCounts('A01', conditionString);
    }

    /**
     *
     * 返回系统中总人数
     *
     */
    async SelectCount() {
        let conditionString = `where A0163 = \'现职人员\' and  ( A0101 is not ''  and A0101 is not null ) `;
        // console.log(conditionString)
        return await this.dal.androidCounts('A01', conditionString);
    }

    /**
     * 返回指定民族的人数
     * @param {Object} EthnicEText 民族 中文文字
     */
    async SelectCountByEthnicE(EthnicEText) {
        let conditionString = "";

        conditionString = `WHERE A0163 = \'现职人员\' and A0117 = \'${EthnicEText}\'  `;
        //console.log(conditionString)
        return await this.dal.androidCounts('A01', conditionString);
    }

    /**
     * 返回指定政治面貌的人数 中共党员 九三学社 民革之类的
     * @param {Object} PoliticsStatusText 政治面貌 中文文字
     */
    async SelectCountByPoliticsStatus(PoliticsStatusText) {
        let conditionString = `WHERE A0163 = \'现职人员\' and A0141 = \'${PoliticsStatusText}\'  `;

        return await this.dal.androidCounts('A01', conditionString);
    }

    /**
     * 返回指定年龄区间的人数
     * @param {Object} beginDate 最早出生时间
     * @param {Object} endDate 最晚出生时间
     */
    async SelectCountByAgeRange(beginDate, endDate) {
        let conditionString = `WHERE A0163 = \'现职人员\' and A01.A0107 >= \'${beginDate}\' and A01.A0107 <= \'${endDate}\' ORDER BY A01.A0107  `;

        return await this.dal.androidCounts('A01', conditionString);
    }

    /**
     * 查询指定工龄区间的人数
     * @param {Object} beginDate
     * @param {Object} endDate
     */
    async SelectCountByWorkingAgeRange(beginDate, endDate) {

        let conditionString = `WHERE A0163 = \'现职人员\' and A01.A0134 >= \'${beginDate}\' and A01.A0134 <= \'${endDate}\' ORDER BY A01.A0134  `;

        return await this.dal.androidCounts('A01', conditionString);
    }

    //#endregion


    // tempSelectString = ` SELECT A01.A0000,A01.ZZXL,A01.ZZXLXX,A01.ZZXW,A01.ZZXWXX,A01.QRZXL,A01.QRZXLXX,A01.QRZXW,A01.QRZXWXX,A01.A0101,A01.A0104,A01.A0192A,A02.A0201A, A02.A0215A,A02.A0225,B01.SORTID as orgSortid,
	// A02.A0201B,A01.A0107,A01.A0111A,A01.A0134,A01.A0140,A01.A0221,A01.A0192E,A01.Y0001,A01.Y0002,A01.Y0003,A01.Y0004,A01.Y0005,A01.Y0006,A01.A0288,A01.A0192C,A01.a0192x,A01.TORGID `
    
    // tempSimpleInfoString = ` SELECT A01.A0000,A01.ZZXL,A01.ZZXLXX,A01.ZZXW,A01.ZZXWXX,A01.QRZXL,A01.QRZXLXX,A01.QRZXW,A01.QRZXWXX,A01.A0101,A01.A0104,A01.A0192A,A01.A0107,A01.A0111A,A01.A0134,A01.A0140,A01.A0221,A01.A0192E,A01.Y0001,A01.Y0002,A01.Y0003,A01.Y0004,A01.Y0005,A01.Y0006,A01.A0288,A01.A0192C,A01.a0192x,A01.TORGID `;
    

    tempSelectString = ` SELECT A01.A0000,A01.ZZXL,A01.ZZXLXX,A01.ZZXW,A01.ZZXWXX,A01.QRZXL,A01.QRZXLXX,A01.QRZXW,A01.QRZXWXX,A01.A0101,A01.A0104,A01.A0192A,A02.A0201A, A02.A0215A,A02.A0225,B01.SORTID as orgSortid,
	A02.A0201B,A01.A0107,A01.A0111A,A01.A0134,A01.A0140,A01.A0221,A01.A0192E,A01.Y0001,A01.Y0002,A01.Y0003,A01.Y0004,A01.Y0005,A01.Y0006,A01.A0288,A01.A0192C,A01.a0192x,A01.TORGID,
    CASE
		
		WHEN LENGTH( A0201B ) >= 15 THEN
		( SELECT B01.SORTID FROM B01 WHERE B0111 = substr( A0201B, 0, 16 ) ) ELSE 0 
	END AS SORTID1,
CASE
		
		WHEN LENGTH( A0201B ) >= 19 THEN
		( SELECT B01.SORTID FROM B01 WHERE B0111 = substr( A0201B, 0, 20 ) ) ELSE 0 
	END AS SORTID2,
CASE
		
		WHEN LENGTH( A0201B ) >= 23 THEN
		( SELECT B01.SORTID FROM B01 WHERE B0111 = substr( A0201B, 0, 24 ) ) ELSE 0
	END AS SORTID3,
CASE
		
		WHEN LENGTH( A0201B ) >= 27 THEN
		( SELECT B01.SORTID FROM B01 WHERE B0111 = substr( A0201B, 0, 28 ) ) ELSE 0 
	END AS SORTID4,
CASE
		
		WHEN LENGTH( A0201B ) >= 31 THEN
		( SELECT B01.SORTID FROM B01 WHERE B0111 = substr( A0201B, 0, 32 ) ) ELSE 0
	END AS SORTID5,
CASE
		
		WHEN LENGTH( A0201B ) >= 35 THEN
		( SELECT B01.SORTID FROM B01 WHERE B0111 = substr( A0201B, 0, 36 ) ) ELSE 0 
	END AS SORTID6  `
    
    tempSimpleInfoString = ` SELECT A01.A0000,A01.ZZXL,A01.ZZXLXX,A01.ZZXW,A01.ZZXWXX,A01.QRZXL,A01.QRZXLXX,A01.QRZXW,A01.QRZXWXX,A01.A0101,A01.A0104,A01.A0192A,A01.A0107,A01.A0111A,A01.A0134,A01.A0140,A01.A0221,A01.A0192E,A01.Y0001,A01.Y0002,A01.Y0003,A01.Y0004,A01.Y0005,A01.Y0006,A01.A0288,A01.A0192C,A01.a0192x,A01.TORGID,
    CASE
		
		WHEN LENGTH( A0201B ) >= 15 THEN
		( SELECT B01.SORTID FROM B01 WHERE B0111 = substr( A0201B, 0, 16 ) ) ELSE 0 
	END AS SORTID1,
CASE
		
		WHEN LENGTH( A0201B ) >= 19 THEN
		( SELECT B01.SORTID FROM B01 WHERE B0111 = substr( A0201B, 0, 20 ) ) ELSE 0 
	END AS SORTID2,
CASE
		
		WHEN LENGTH( A0201B ) >= 23 THEN
		( SELECT B01.SORTID FROM B01 WHERE B0111 = substr( A0201B, 0, 24 ) ) ELSE 0
	END AS SORTID3,
CASE
		
		WHEN LENGTH( A0201B ) >= 27 THEN
		( SELECT B01.SORTID FROM B01 WHERE B0111 = substr( A0201B, 0, 28 ) ) ELSE 0 
	END AS SORTID4,
CASE
		
		WHEN LENGTH( A0201B ) >= 31 THEN
		( SELECT B01.SORTID FROM B01 WHERE B0111 = substr( A0201B, 0, 32 ) ) ELSE 0
	END AS SORTID5,
CASE
		
		WHEN LENGTH( A0201B ) >= 35 THEN
		( SELECT B01.SORTID FROM B01 WHERE B0111 = substr( A0201B, 0, 36 ) ) ELSE 0 
	END AS SORTID6  `;
    


    tempFromString = ` FROM A01,A02,B01 `;
    
    tempWhereString = ` where ((A01.A0000 =  A02.A0000 ) and (A02.A0201B = B01.B0111) and  A02.A0281 = 'true'  ) `;
    //tempOrderString = ` ORDER BY B01.B0127,B01.B0124,B01.B0131, LENGTH(B01.SORTID), B01.SORTID,LENGTH(A02.A0225),A02.A0225 `;//ORDER BY B01.B0127,B01.B0124,B01.B0131,  B01.SORTID,A02.A0225
    
    //tempOrderString = ` ORDER BY LENGTH(A02.A0201B), LENGTH(B01.SORTID), B01.SORTID,LENGTH(A02.A0225),A02.A0225 `;
    tempOrderString = ` ORDER BY  LENGTH( SORTID1 ),
                        SORTID1,
                        LENGTH( SORTID2 ),
                        SORTID2,
                        LENGTH( SORTID3 ),
                        SORTID3,
                        LENGTH( SORTID4 ),
                        SORTID4,
                        LENGTH( SORTID5 ),
                        SORTID5,
                        LENGTH( SORTID6 ),
                        SORTID6,
                        LENGTH( A02.A0225 ),
                        A02.A0225 `;
    //#region 查询简单信息



    async SelectPersionSimpleInfosByCondition2(condition, isOnlyPersionID) {
        let tempSqlString = '';
        //拼接 select部分
        if (isOnlyPersionID) {
            tempSqlString = 'SELECT A01.A0000 ';
        } else {
            tempSqlString = this.tempSimpleInfoString;
        }

        //拼接from部分
        tempSqlString += this.tempFromString;

        //拼接where之类的condition部分

        tempSqlString += this.tempWhereString;

        tempSqlString += ' ' + condition + ' ';

        //拼接排序部分
        if (!isOnlyPersionID){
            tempSqlString += this.tempOrderString;
        }


        //console.log(tempSqlString)
        let temp = await this.dal.SelectDataFieldArrayFromDBByCmd(tempSqlString);
        //console.log(temp)
        return this.toCanRead(this.removeSamePersion(temp));
    }

    removeSamePersion(infosArray) {
        let mySet = new Set()
        let tempArray = new Array();
        for (let i = 0; i < infosArray.length; i++) {
            let persionID = infosArray[i].A0000;
            if (!mySet.has(persionID)) {
                let persionID = infosArray[i].A0000;
                mySet.add(persionID);
                tempArray.push(infosArray[i]);
            }
        }
        return tempArray;
    }

    async GetPersionSimpleInfosIncludBranchOrgByOrgID(orgid) {
        let conditionString = `and ( A01.A0163 = \'现职人员\' and A02.A0201B like \'${orgid}%\'  ) `;
        return await this.SelectPersionSimpleInfosByCondition2(conditionString, false);
    }

    /**
     * 返回少数民族人员简单信息
     *
     */
    async SelectMinorityPersonSimpleInfo(isOnlyPersionID) {
        // let conditionString = `WHERE A0163 = \'现职人员\' and A0117 != \'汉族\'  `;

        // return await this.SelectPersionSimpleInfosByCondition(conditionString, isOnlyPersionID);

        //return this.toCanRead( await this.dal.SelectDataArrayFromDB('A01',conditionString));

        let conditionString = `and A01.A0165 is not '其他' and ( A01.A0163 = \'现职人员\' and A01.A0117 != \'汉族\')  `;
        return await this.SelectPersionSimpleInfosByCondition2(conditionString, isOnlyPersionID);
    }


    /**
     * 返回指定年龄区间的人员简单信息
     * @param {Object} beginDate 最早出生时间
     * @param {Object} endDate 最晚出生时间
     */
    async SelectSimplePersionInfoByAgeRange(beginDate, endDate, isOnlyPersionID) {
        // let conditionString = `WHERE A0163 = \'现职人员\' and A01.A0107 >= \'${beginDate}\' and A01.A0107 <= \'${endDate}\' ORDER BY A01.A0107  `;

        // return await this.SelectPersionSimpleInfosByCondition(conditionString, isOnlyPersionID);

        let conditionString = ` and A01.A0165 is not '其他' and (A01.A0163 = \'现职人员\' and A01.A0107 >= \'${beginDate}\' and A01.A0107 <= \'${endDate}\' )  `;
        console.log(conditionString)
        console.log('isOnlyPersionID '+isOnlyPersionID)
        return await this.SelectPersionSimpleInfosByCondition2(conditionString, isOnlyPersionID);
    }

    /**
     * 返回指定年龄区间的人员简单信息
     * @param {Object} beginDate 最早出生时间
     * @param {Object} endDate 最晚出生时间
     */
    async SelectSimplePersionInfoXian(beginDate, endDate, isOnlyPersionID) {
        // let conditionString = `WHERE ( A0163 = \'现职人员\' and A01.A0107 >= \'${beginDate}\' and A01.A0107 <= \'${endDate}\' ) AND (A0221 in('县处级正职','县处级副职') or A0192E in ('一级调研员','二级调研员','三级调研员','四级调研员','二级总监','一级高级主管','二级高级主管','三级高级主管','一级高级主办','二级高级主办','三级高级主办','四级高级主办','一级高级警长','二级高级警长','三级高级警长','四级高级警长','警务技术二级主任','警务技术三级主任','警务技术四级主任','一级高级法官','二级高级法官','三级高级法官','四级高级法官','一级高级检察官','二级高级检察官','三级高级检察官','四级高级检察官','督办','五级职员','六级职员')) ORDER BY A01.A0107  `;

        // return await this.SelectPersionSimpleInfosByCondition(conditionString, isOnlyPersionID);


        let conditionString = ` and A01.A0165 is not '其他' and ( ( A01.A0163 = \'现职人员\' and A01.A0107 >= \'${beginDate}\' and A01.A0107 <= \'${endDate}\' ) AND (A01.A0221 in('县处级正职','县处级副职') or A0192E in ('一级调研员','二级调研员','三级调研员','四级调研员','二级总监','一级高级主管','二级高级主管','三级高级主管','一级高级主办','二级高级主办','三级高级主办','四级高级主办','一级高级警长','二级高级警长','三级高级警长','四级高级警长','警务技术二级主任','警务技术三级主任','警务技术四级主任','一级高级法官','二级高级法官','三级高级法官','四级高级法官','一级高级检察官','二级高级检察官','三级高级检察官','四级高级检察官','督办','五级职员','六级职员')))   `;

        return await this.SelectPersionSimpleInfosByCondition2(conditionString, isOnlyPersionID);
    }

    /**
     * 查询指定工龄区间的人员简单信息
     * @param {Object} beginDate
     * @param {Object} endDate
     */
    async SelectSimplePersionInfoByWorkingAgeRange(beginDate, endDate, isOnlyPersionID) {

        // let conditionString = `WHERE A0163 = \'现职人员\' and A01.A0134 >= \'${beginDate}\' and A01.A0134 <= \'${endDate}\' ORDER BY A01.A0134  `;
        // //console.log(conditionString)
        // return await this.SelectPersionSimpleInfosByCondition(conditionString, isOnlyPersionID);

        let conditionString = ` and A01.A0165 is not '其他' and ( A01.A0163 = \'现职人员\' and A01.A0134 >= \'${beginDate}\' and A01.A0134 <= \'${endDate}\' )  `;
        //console.log(conditionString)
        return await this.SelectPersionSimpleInfosByCondition2(conditionString, isOnlyPersionID);
    }

    /**
     * 查指定奖惩的人的简单信息
     * @param {*} nativePlaceName 籍贯
     * @param {*} isOnlyPersionID
     */
    async SelectPersonSimpleInfoByRewardsAndPunishment(nativePlaceName, isOnlyPersionID) {
        // let conditionString = `WHERE A0163 = \'现职人员\' and A14Z101 like \'%${nativePlaceName}%\'  `;
        // console.log(conditionString)
        // return await this.SelectPersionSimpleInfosByCondition(conditionString, isOnlyPersionID);

        //return this.toCanRead( await this.dal.SelectDataArrayFromDB('A01',conditionString));

        let conditionString = ` and A01.A0165 is not '其他' and (A01.A0163 = \'现职人员\' and A01.A14Z101 like \'%${nativePlaceName}%\'  ) `;
        console.log(conditionString)
        return await this.SelectPersionSimpleInfosByCondition2(conditionString, isOnlyPersionID);
    }

    /**
     * 返回指定民族的人员简单信息，汉族 蒙古族
     * @param {*} isOnlyPersionID
     */
    async SelectPersonSimpleInfoByEthnic(EthnicName, isOnlyPersionID) {
        // let conditionString = `WHERE A0163 = \'现职人员\' and A0117 = \'${EthnicName}\'  `;

        // return await this.SelectPersionSimpleInfosByCondition(conditionString, isOnlyPersionID);

        //return this.toCanRead( await this.dal.SelectDataArrayFromDB('A01',conditionString));

        let conditionString = ` and A01.A0165 is not '其他' and ( A01.A0163 = \'现职人员\' and A01.A0117 = \'${EthnicName}\' )  `;

        return await this.SelectPersionSimpleInfosByCondition2(conditionString, isOnlyPersionID);
    }

    /**
     * 返回中共党员的简单信息
     *
     */
    async SelectCCPSimplePersionInfo(isOnlyPersionID) {
        // let conditionString = `WHERE A0163 = \'现职人员\' and A0141 = \'中共党员\'  `;

        // return await this.SelectPersionSimpleInfosByCondition(conditionString, isOnlyPersionID);


        let conditionString = ` and A01.A0165 is not '其他' and ( A01.A0163 = \'现职人员\' and A01.A0141 = \'中共党员\' ) `;

        return await this.SelectPersionSimpleInfosByCondition2(conditionString, isOnlyPersionID);
    }


    /**
     * 返回不是中共党员的人的简单信息
     * @param {Object} PoliticsStatusText 政治面貌 中文文字
     */
    async SelectNotCCPSimplePersionInfo(isOnlyPersionID) {
        // let conditionString = `WHERE A0163 = \'现职人员\' and A0141 is not \'中共党员\'  `;

        // return await this.SelectPersionSimpleInfosByCondition(conditionString, isOnlyPersionID);

        let conditionString = ` and A01.A0165 is not '其他' and ( A01.A0163 = \'现职人员\' and A01.A0141 is not \'中共党员\' ) `;

        return await this.SelectPersionSimpleInfosByCondition2(conditionString, isOnlyPersionID);
    }


    /**
     * 返回指定人员类别的人员简单信息
     * @param {*} personType ['公务员','参照管理机关工作人员','事业单位管理人员','参照管理事业单位人员','其他人员','企业管理人员']
     * @param {*} isOnlyPersionID
     */
    async SelectSimplePersionInfoByPersonType(personTypeArray, isOnlyPersionID) {

        // let tempQueryString = "WHERE A0163 = \'现职人员\' and A0160 in ( ";
        // for (let i = 0; i < personTypeArray.length; i++) {
        // 	tempQueryString += `\'${personTypeArray[i]}\',`;
        // }
        // tempQueryString = tempQueryString.substring(0, tempQueryString.length - 1);
        // tempQueryString += ")";

        // return await this.SelectPersionSimpleInfosByCondition(tempQueryString, isOnlyPersionID);


        let tempQueryString = " and A01.A0165 is not '其他' and (  A01.A0163 = \'现职人员\' and A01.A0160 in ( ";
        for (let i = 0; i < personTypeArray.length; i++) {
            tempQueryString += `\'${personTypeArray[i]}\',`;
        }
        tempQueryString = tempQueryString.substring(0, tempQueryString.length - 1);
        tempQueryString += ") )";

        return await this.SelectPersionSimpleInfosByCondition2(tempQueryString, isOnlyPersionID);
    }


    /**
     * 查询指定性别人的人员信息 参数是男女文字 不是数字代码
     * @param {Object} sexText 男 女
     */
    async SelectPersionSimpleInfosBySex(sexText, isOnlyPersionID) {
        let conditionString = ` and A01.A0165 is not '其他' and (A01.A0163 = \'现职人员\' and A01.A0104 = \'${sexText}\' )  `;

        //return await this.dal.SelectDataArrayFromDB('A01',tempQueryString);
        return this.SelectPersionSimpleInfosByCondition2(conditionString, isOnlyPersionID)
        //return this.toCanRead(await this.dal.SelectDataArrayFromDB('A01',conditionString))
    }

    /**
     * 查询指定ID的人员简单信息
     *
     */
    async SelectPersionSimpleInfosByPersionID(persionID) {
        // let conditionString = `WHERE A0163 = \'现职人员\' and A0000 = \'${persionID}\'  `;

        // //return await this.dal.SelectDataArrayFromDB('A01',tempQueryString);
        // return this.SelectPersionSimpleInfosByCondition(conditionString, false)
        //return this.toCanRead(await this.dal.SelectDataArrayFromDB('A01',conditionString))


        let conditionString = ` and ( A01.A0163 = \'现职人员\' and A01.A0000 = \'${persionID}\' ) `;

        //return await this.dal.SelectDataArrayFromDB('A01',tempQueryString);
        return this.SelectPersionSimpleInfosByCondition2(conditionString, false)
    }

    /**
     * 按职务等级查人的简单信息
     * @param {*} LeaderLevelArray ['厅局级正职','厅局级副职','乡科级正职','乡科级副职','县处级正职','县处级副职']
     */
    async SelectPersionSimpleInfoByLeaderLevel(LeaderLevelArray, isOnlyPersionID) {
        // let tempQueryString = "WHERE A0163 = \'现职人员\' and A0221 in ( ";
        // for (let i = 0; i < LeaderLevelArray.length; i++) {
        // 	tempQueryString += `\'${LeaderLevelArray[i]}\',`;
        // }
        // tempQueryString = tempQueryString.substring(0, tempQueryString.length - 1);
        // tempQueryString += ")";

        // return await this.SelectPersionSimpleInfosByCondition(tempQueryString, isOnlyPersionID);


        let tempQueryString = " and A01.A0165 is not '其他' and   (A01.A0163 = \'现职人员\' and A01.A0221 in ( ";
        for (let i = 0; i < LeaderLevelArray.length; i++) {
            tempQueryString += `\'${LeaderLevelArray[i]}\',`;
        }
        tempQueryString = tempQueryString.substring(0, tempQueryString.length - 1);
        tempQueryString += ") )";

        return await this.SelectPersionSimpleInfosByCondition2(tempQueryString, isOnlyPersionID);
    }


    /**
     * 按职级查人的简单信息
     * @param {*} LeaderLevelArray ['一级调研员','二级调研员','三级调研员','四级调研员','一级主任科员','二级主任科员']
     */
    async SelectPersionSimpleInfoByJobLevel(JobLevelArray, isOnlyPersionID) {
        // let tempQueryString = "WHERE A0163 = \'现职人员\' and A0192E in ( ";
        // for (let i = 0; i < JobLevelArray.length; i++) {
        // 	tempQueryString += `\'${JobLevelArray[i]}\',`;
        // }
        // tempQueryString = tempQueryString.substring(0, tempQueryString.length - 1);
        // tempQueryString += ")";

        // return await this.SelectPersionSimpleInfosByCondition(tempQueryString, isOnlyPersionID);


        let tempQueryString = " and ( A01.A0163 = \'现职人员\' and A01.A0192E in ( ";
        for (let i = 0; i < JobLevelArray.length; i++) {
            tempQueryString += `\'${JobLevelArray[i]}\',`;
        }
        tempQueryString = tempQueryString.substring(0, tempQueryString.length - 1);
        tempQueryString += ") )";

        return await this.SelectPersionSimpleInfosByCondition2(tempQueryString, isOnlyPersionID);
    }


    /**
     * 查指定籍贯的人的简单信息
     * @param {*} rewardsAndPunishmentKey 简称关键字
     */
    async SelectPersonSimpleInfoByNativePlace(nativePlaceName, isOnlyPersionID) {
        // let conditionString = `WHERE A0163 = \'现职人员\' and A0111A like \'%${nativePlaceName}%\'  `;

        // return await this.SelectPersionSimpleInfosByCondition(conditionString, isOnlyPersionID);

        //return this.toCanRead( await this.dal.SelectDataArrayFromDB('A01',conditionString));

        let conditionString = ` and ( A01.A0163 = \'现职人员\' and A01.A0111A like \'%${nativePlaceName}%\' ) `;

        return await this.SelectPersionSimpleInfosByCondition2(conditionString, isOnlyPersionID);
    }


    async SelectPersionSimpleInfosByCondition(condition, isOnlyPersionID) {
        if (isOnlyPersionID === true) {
            let temp = await this.dal.SelectDataFieldArrayFromDB('A01', 'A0000', condition);

            return this.toCanRead(temp);
        } else {
            let temp = await this.dal.SelectDataFieldArrayFromDB('A01', 'A0000,A0101,A0104,A0192A,A0107,A0111A,A0134,A0140,A0221,A0192E,Y0001,Y0002,Y0003,Y0004,Y0005,Y0006,A0288,A0192C,a0192x,TORGID', condition);
            return this.toCanRead(temp);
        }
    }


    /**
     * 通过身份证数组查询人，用在收藏夹功能上。收藏夹文件存的是身份证号
     * @param {Object} IDCardNOs 参数是一个数组  ['410504197001010001','410504198001010001'] 代表两个人
     * 返回的是人员的简要信息
     */
    async SelectPersionSimpleInfoByIDCardNO(IDCardNOArray, isOnlyPersionID) {
        // let tempQueryString = "WHERE  A0184 in ( ";
        // for (let i = 0; i < IDCardNOArray.length; i++) {
        // 	tempQueryString += `\'${IDCardNOArray[i]}\',`;
        // }
        // tempQueryString = tempQueryString.substring(0, tempQueryString.length - 1);
        // tempQueryString += ")";
        // return await this.SelectPersionSimpleInfosByCondition(tempQueryString, isOnlyPersionID);//A0163 = \'现职人员\' and


        let tempQueryString = " and (  A01.A0184 in ( ";
        for (let i = 0; i < IDCardNOArray.length; i++) {
            tempQueryString += `\'${IDCardNOArray[i]}\',`;
        }
        tempQueryString = tempQueryString.substring(0, tempQueryString.length - 1);
        tempQueryString += ") )";
        return await this.SelectPersionSimpleInfosByCondition2(tempQueryString, isOnlyPersionID);//A0163 = \'现职人员\' and
    }


    /**
     * 查询一组干部简要信息，可以用在查询列表上
     * @param {Object} idArray
     * 返回 A01表格主要信息字段
     */
    async SelectPersionSimpleInfosByPersionIDArray(idArray) {//A0163 = \'现职人员\' and

        let tempQueryString = "and ( A01.A0000 in ( ";
        for (let i = 0; i < idArray.length; i++) {
            tempQueryString += `\'${idArray[i]}\',`;
        }

        tempQueryString = tempQueryString.substring(0, tempQueryString.length - 1);
        tempQueryString += ") )";

        return await this.SelectPersionSimpleInfosByCondition2(tempQueryString, false);
    }

    /**
     * 查询一组干部简要信息，可以用在查询列表上
     * @param {Object} idArray
     * 返回 A01表格主要信息字段
     */
    async SelectAllPersionSimpleInfos() {
        // let tempQueryString = "WHERE A0163 = \'现职人员\' ";

        // //console.log(tempQueryString)
        // return await this.SelectPersionSimpleInfosByCondition(tempQueryString, false);


        let tempQueryString = " and  A01.A0163 = \'现职人员\' ";

        //console.log(tempQueryString)
        return await this.SelectPersionSimpleInfosByCondition2(tempQueryString, false);

    }

    //#endregion


    // and (A01.A0163 = '现职人员')

    makeEncryptString(originalKey) {
        console.log(originalKey[0])
        let tempString = '';
        if (originalKey && originalKey.length > 0) {
            for (let i = 0; i < originalKey.length; i++) {

                tempString += this.aCryptoFile.encrypt(originalKey[i]) + '@1@2';
            }
        }
        return tempString;
    }

    /* @param {Object} persionName
     * 5.查询干部姓名  干部姓名拼音  干部姓名拼音简写 查询到符合检索条件的干部ID
     * 返回persionid数组 A0000
     */
    async SelectPersionIDByPersionName(persionName) {
        let encryptPersionName = this.makeEncryptString(persionName);

        // let temp = await this.dal.SelectDataFieldArrayFromDB('A01', 'DISTINCT A0000', `WHERE A0163 = \'现职人员\' and
        // 								(	A01.A0101 LIKE \'%${persionName}%\' OR
        // 									A01.X0001 LIKE \'%${persionName}%\' OR
        // 									A01.X0002 LIKE \'%${persionName}%\' ) `);
        let temp = await this.dal.SelectDataFieldArrayFromDB('A01', 'DISTINCT A0000', `WHERE  
		    ( A01.A0101 LIKE \'%${encryptPersionName}%\' OR
			A01.A0102 LIKE \'%${encryptPersionName}%\' ) `);
        return this.toCanRead(temp);
    }

    /**
     * 查询一组干部详细信息
     * @param {Object} idArray 干部ID数组
     * 返回 A01表格全部字段
     */
    async SelectPersionDetailInfosByPersionIDArray(idArray) {
        if (idArray.length == 0) {
            return [];
        }

        let tempQueryString = '';
        //这样写是为了查单人时加快查询速度  A0163 = \'现职人员\' and
        if (idArray.length == 1) {
            tempQueryString = `WHERE  A0000 = \'${idArray[0]}\'  `;
        } else {
            tempQueryString = "WHERE  A0000 in ( ";
            for (let i = 0; i < idArray.length; i++) {
                tempQueryString += `\'${idArray[i]}\',`;
            }

            tempQueryString = tempQueryString.substring(0, tempQueryString.length - 1);
            tempQueryString += ")";
        }


        let infosArray = await this.dal.SelectDataArrayFromDB('A01', tempQueryString);
        return this.toCanRead(infosArray);
        //return

    }

}

export default A01DAL;